LOAD DATA

Add variables to the existing dataset.

15 minute volume takes the VMT for each time bin and divides by the length of the segment. Unit: Vehicles per mile. Speed is the segment length divided by the travel time ( * 60). Unit: Miles per hour. Hourly_Flow is the 15 minute volume multipled by 4 and divided by the number of lanes. Unit: Vehicles per hour. Density is the Hourly Flow divided by speed. Unit: Vehicles per hour.

We also create a variable that measures the delay type experienced by the segment. Weather (snow) events and crashes were tracked for the time period. If the segment experiences a weather event and a crash, weather will be the controlling delay type.

Segments <- DBI::dbReadTable(drv, 'Segments_494') %>%
  filter(!is.na(Length)) %>%
  select(Segment = Segment_No, Lanes, Length) %>%
  arrange(Segment)

Data_494 <- merge(Data_494, Segments, by = 'Segment')

Rel <- Data_494 %>% mutate(Vol_15_min  = VMT_total/Length,
                           Speed       = Length/TT_mean*60,
                           Hourly_Flow = Vol_15_min*4/Lanes,
                           Dens        = Hourly_Flow/Speed,
                           Hour        = as.factor(format(DateTime,format = '%H')),
                           Month       = as.factor(format(DateTime,format = '%m')),
                           WeekDay     = as.factor(weekdays(DateTime)),
                           DateTimeSec = as.numeric(DateTime),
                           Delay_type  = (ifelse(weather == 1, 
                                                'Weather',
                                                ifelse(Crash == 1, 
                                                       'Crash',
                                                       'None'))),
                           is_Delay       = ifelse(Delay_type == 'None', 'No_Delay', 'Delay'),
                           Index = seq(1,length(Speed),1)) %>%
  filter(!is.na(DateTime))
ggplot(Rel,aes(x = as.factor(Segment),y = TT_mean)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(alpha = 0.5)

# Rel %>%
#   filter(Segment == 9) %>%
#   arrange(desc(TT_mean)) %>%
#   print(n=20)
bins <- c(seq(floor(min(Rel$Dens)),50,2),60,70,80,90,100,125,150,200,300,400,480)


#1S
# bins <- c(seq(floor(min(Rel_2014$Dens)),50,2),
#           60,70,80,100,125,150,round(max(Rel_2014$Dens)+1,0))

Rel$cut <- cut(Rel$Dens,bins,echo.lowest = TRUE)
Rel$Density_bin <- as.numeric(stringi::stri_match_last_regex(Rel$cut,'[0-9]+')) 

d <- Rel %>%
  group_by(Density_bin, Segment) %>%
  summarise(Count = n()) %>%
  arrange(Density_bin) %>%
  dcast(Density_bin ~ Segment)
## Using 'Count' as value column. Use 'value.var' to override

Percentile Bins

We will break down the dataset into each delay type and then further into percentiles.

The percentiles choosen are 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95.

For each quantile a travel time quantile is calculated. We also want to calculate a Free Floew Speed for each quantile.

The Free Flow speeds were calcuated using the 95th percentile speeds.

MAP

FREE FLOW

Segment 1

Segment 2

Segment 3

Segment 4

Segment 5

Segment 6

Segment 7

Segment 8

Segment 9

DENSITY vs TT

A look at the Density vs travel time plots. A generic smooting function has been added.

Segment 1

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 2

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 3

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 4

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 5

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 6

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 7

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 8

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 9

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

DENSITY vs FLOW

Below are the Flow vs Density plots for each condition.

Verical lines show the congestion Density for each condition.

Segment 1

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 2

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 3

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 4

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 5

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 6

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 7

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 8

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

Segment 9

## Warning: Removed 7 rows containing non-finite values (stat_smooth).

MODELMAX

We need to find the congestion point for each Delay type and percentile. ### SEGMENT 1

# model_max <- model %>%
#   group_by(is_Delay,quantiles) %>%
#   # group_by(Delay_type,quantiles) %>%
#   # summarise(max = max(.fitted))
#   filter(.fitted == max(.fitted)) %>%
#   select(is_Delay, quantiles, Cong_Flow = .fitted, Cong_Density = Density_bin)
#   # select(Delay_type, quantiles, Cong_Flow = .fitted, Cong_Density = Density_bin)

HEATMAP

SEGMENT 1

TT_heat(Rel,1)

SEGMENT 2

TT_heat(Rel,2)

SEGMENT 3

TT_heat(Rel,3)

SEGMENT 4

TT_heat(Rel,4)

SEGMENT 5

TT_heat(Rel,5)

SEGMENT 6

TT_heat(Rel,6)

SEGMENT 7

TT_heat(Rel,7)

SEGMENT 8

TT_heat(Rel,8)

SEGMENT 9

TT_heat(Rel,9)